 package controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import service.CustomerManager;
import vo.Customer;



@Controller
public class CustomerController{
	
	@Resource(name = "customerManagerImpl")
	private CustomerManager manager;
	
	public void setManager(CustomerManager manager) {
		this.manager = manager;
	}
	
	
	@RequestMapping(value="/signup")
	public String signup(Customer c){
		if(manager.findCustomerByName(c.getName())!=null){
			return "signup";
		}
		else{
			manager.addCustomer(c);
		}
		return "login";
	}
	
	@RequestMapping(value ="/login")
	public String login(Customer c,Model model){
		Customer customer = manager.findCustomerByNameAndPwd(c.getName(), c.getPwd());
		if(customer==null)return "login";
		else{
			model.addAttribute("name", customer.getName());
			return "suc";
		}   

	}
	
	
	
}
